from .BaseConvert import Convert


class BooleanConvert(Convert):
    field_type = 'boolean'

    @classmethod
    def to_read(cls, rec, field, **kwargs):
        return rec[field.name] in ('true', 'True', 1, '1', 'on', True)

    @classmethod
    def to_field(cls, value,metadata=None, update=False):
        return value in ('true', 'True', 1, '1', 'on', True)

    @classmethod
    def to_domain(cls, field, value, **kwargs):
        if isinstance(value, str):
            if value in ('true', 'True'):
                value = True
            elif value in ('false', 'False'):
                value = False
        elif isinstance(value, bool):
            value = value
        return [(field.name, '=', value)]
